<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>index09-字符串</title>
</head>
<body>
<script type="text/javascript">

    let str = "es6,ni da ye";
    // indexOf 查找字符串中是否包含指定字符串  查找第一次出现的位置，从0开始
    console.log(str.indexOf("da"));
    console.log(str.indexOf("daa"));
    // includes()：返回布尔值，判断是否找到参数字符串。
    console.log(str.includes("da"));
    console.log(str.includes("daa"));
	// startsWith()：返回布尔值，判断参数字符串是否在原字符串的头部。
    console.log(str.startsWith("es6"));
    console.log(str.startsWith("es7"));
	// endsWith()：返回布尔值，判断参数字符串是否在原字符串的尾部。
    console.log(str.endsWith("ye"));
    console.log(str.endsWith("yee"));

    // repeat()——重复字符串
    let str2 = "Hello ";
    console.log(str2.repeat(5));

    // padStart
    // padEnd
    // console.log("11".padStart(5, '0'));
    // console.log("11".padEnd(5, '0'));
    // console.log("11".padStart(5));
    let date = new Date();
    console.log(formatDate(date));

    function formatDate(d){
        let yyyy = d.getFullYear();
        let MM = (d.getMonth() + 1 + "").padStart(2, '0');
        let dd = (d.getDate() + "").padStart(2, '0');
        let HH = (d.getHours() + "").padStart(2, '0');
        let mm = (d.getMinutes() + "").padStart(2, '0');
        let ss = (d.getSeconds() + "").padStart(2, '0');
        return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`;
    }
</script>
</body>
</html>